package com.wangmin.sockets;

import java.net.ServerSocket;
import java.util.ArrayList;
import java.util.List;

public class HandlePull {
	private static HandlePull handlePull;
	private List<Handler> list;
	public static HandlePull getInstance(){
		if(handlePull == null){
			synchronized (ServerSocket.class) {
				if(handlePull == null){
					handlePull = new HandlePull();
				}
			}
		}
		return handlePull;
	}
	
	private HandlePull(){
		list = new ArrayList<Handler>();
	}
	
	public synchronized void addPull(Handler handler){
		list.add(handler);
	}
	
	public synchronized void removePull(Handler handler){
		list.remove(handler);
	}
	
	public Handler getHandle(String ip){
		Handler lHandler = null;
		for(Handler handler:list){
			if(handler.getIp().equals(ip)){
				lHandler = handler;
				break;
			}
		}
		return lHandler;
	}
}
